"""
Case Type   : 功能测试
Case Name   : to_char (string)将localtimestamp转换为timestamp类型并保留3、6位小数
Create At   : 2024/7/6
Owner       : liu-tong-8848
Description :
    1.to_char (string)将localtimestamp转换为timestamp类型并保留3、6位小数
Expect      :
    1.成功
History     :
"""

import os
import unittest
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Logger import Logger


class PACKAGE(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.primary_sh = CommonSH('PrimaryDbUser')

    def test_package(self):
        self.logger.info(f'-----{os.path.basename(__file__)} start-----')
        step = 'step1:to_char (string)将localtimestamp转换为timestamp类型并保留3、6位小数 expect:成功'
        self.logger.info(step)
        select_3_msg = self.primary_sh.execut_db_sql(
            f'''select to_char(localtimestamp,'YYYY-MM-DD HH24:MI:SS.FF3');''')
        self.logger.info(select_3_msg)
        type_number = len(select_3_msg.splitlines()[-2].split(".")[1])
        self.assertEqual(3, type_number, '执行失败' + step)
        select_6_msg = self.primary_sh.execut_db_sql(
            f'''select to_char(localtimestamp,'YYYY-MM-DD HH24:MI:SS.FF6');''')
        self.logger.info(select_6_msg)
        type_number = len(select_6_msg.splitlines()[-2].split(".")[1])
        self.assertEqual(6, type_number, '执行失败' + step)

    def tearDown(self):
        self.logger.info(f'-----{os.path.basename(__file__)} end-----')
